@page "/pizzas"
@using BlazingPizza.Data
@inject PizzaService PizzaSvc

<h1>Choose your pizza</h1>
<p>We have all these delicious recipes:</p>

@if (todaysPizzas == null)
{
    <p>We're finding out what pizzas are available today...</p>
}
else
{
    <table>
        <thead>
            <tr>
                <th>Pizza Name</th>
                <th>Description</th>
                <th>Vegetarian?</th>
                <th>Vegan?</th>
                <th>Price</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var pizza in todaysPizzas)
            {
                <tr>
                    <td>@pizza.Name</td>
                    <td>@pizza.Description</td>
                    <td>@pizza.Vegetarian</td>
                    <td>@pizza.Vegan</td>
                    <td>@pizza.Price</td>
                </tr>
            }
        </tbody>
    </table>
}

@code {

    private string str = "A";
    private Pizza[] todaysPizzas;

    //调用服务和获取数据的好位置,当组件初始化完成且收到初始参数时,在呈现页面并显示给用户之前,将触发此事件
    protected override async Task OnInitializedAsync()
    {
        //Call the service here
        todaysPizzas = await PizzaSvc.GetPizzasAsync();
    }
}
